/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.DAOs;

import com.ControlEscolar.Beans.GroupDetail;
import java.util.ArrayList;

/**
 *
 * @author Rodna Marrufo
 */
public class GroupDetailDAO extends AbstractDAO <GroupDetail>{

    @Override
    public void add(GroupDetail object) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int delete(String condition) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int update(GroupDetail object) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<GroupDetail> query() throws DAOException {
          try {
            String sql = "SELECT g.groupName,s.subjectName,p.professor_name, g.state FROM groups g " +
                    "LEFT JOIN (subjects s, professors p)ON(g.ID_Professor=p.ID_Professor and s.subjectKey=g.subjectKey)";
            return connection.executeQuery(sql, GroupDetail.class);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }

    public GroupDetail queryByName(String groupName) throws DAOException{
        try {
            String sql = "SELECT g.groupName,s.subjectName,p.professor_name, g.state FROM groups g " +
                    "LEFT JOIN (subjects s, professors p)ON(g.ID_Professor=p.ID_Professor and s.subjectKey=g.subjectKey) where g.groupName=\""
                    +groupName+"\"";
            ArrayList<GroupDetail> groupDetailQuery = connection.executeQuery(sql, GroupDetail.class);
            return getSpecificQuery(groupDetailQuery);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }

    public ArrayList<GroupDetail> queryStudentGroupsDetailedAvailable (ArrayList <String> subjects)throws DAOException {
         try {
             int subjectKey;
             String sql = "SELECT g.groupName,s.subjectName,p.professor_name, g.state FROM groups g " +
                    "LEFT JOIN (subjects s, professors p)ON(g.ID_Professor=p.ID_Professor and s.subjectKey=g.subjectKey) where ";
            for(subjectKey=0; subjectKey<subjects.size()-1;subjectKey++){
                sql+="g.subjectKey = \""+subjects.get(subjectKey)+"\" or ";
            }
             sql+="g.subjectKey= \""+subjects.get(subjectKey)+"\" and g.state=\"A\"";
            return connection.executeQuery(sql, GroupDetail.class);

        } catch (Exception ex) {
            throw new DAOException();

        }
    }

}
